package com.dctp.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.resend.Resend;
import com.resend.core.exception.ResendException;
import com.resend.services.emails.model.CreateEmailOptions;
import com.resend.services.emails.model.CreateEmailResponse;

public class EmailSender {

    private static final Logger logger = LoggerFactory.getLogger(EmailSender.class);

    private static Resend resend = new Resend("re_enBAyezw_7YNjNgVRXfJDvDgt5DYEtHiY");

    public static String sendEmail(String vcode,String email) {
        CreateEmailOptions params = CreateEmailOptions.builder()
                .from("Trader@traderder.com")
                .to(email)
                .subject("Trader 验证码")
                .html("<h3>欢迎使用 Trader</h3><p>您的验证码是: <strong>" + vcode + "</strong></p>")
                .build();

        try {
            CreateEmailResponse data = resend.emails().send(params);
            return data.getId();
        } catch (ResendException e) {
            logger.error("Failed to send email: {}", e.getMessage());
            return null;
        }
    }

    public static void main(String[] args) {
        sendEmail("123456", "695801662@qq.com");
    }
}
